import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { globalStore } from '@ds/ds-micro/dist';

@Component({
  selector: 'app-customer-add',
  templateUrl: './customer-add.component.html',
  styleUrls: ['./customer-add.component.less'],
})
export class CustomerAddComponent implements OnInit {
  i = 0;
  onChange = null;

  constructor(
    private cdr: ChangeDetectorRef
  ) {}

  ngOnInit(): void {
    this.onChange = globalStore().subscribe(v => {
      console.log('子应用看到来自main内部变化:', v);
      this.i = v?.data;
      this.cdr.detectChanges();
    });
  }

  iChange(ev) {
    globalStore().next({ 'customer-add': ev });
  }

  ngOnDestroy(): void {
    if(this.onChange) {
      this.onChange.unsubscribe();
    }
  }
}
